package com.mujin.keji.collectionsystem.db.database;

import android.arch.persistence.room.Database;
import android.arch.persistence.room.Room;
import android.arch.persistence.room.RoomDatabase;
import android.content.Context;

import com.mujin.keji.collectionsystem.db.dao.SignDao;
import com.mujin.keji.collectionsystem.db.dao.UserDao;
import com.mujin.keji.collectionsystem.db.dao.VisitDao;
import com.mujin.keji.collectionsystem.db.dao.VisitRecordDao;
import com.mujin.keji.collectionsystem.db.dao.VisitRuleDao;
import com.mujin.keji.collectionsystem.db.domain.SaveVisitRecordBean;
import com.mujin.keji.collectionsystem.db.domain.SignBean;
import com.mujin.keji.collectionsystem.db.domain.VisitApplyBean;
import com.mujin.keji.collectionsystem.db.domain.VisitApplyDetailBean;
import com.mujin.keji.collectionsystem.db.domain.VisitApplyMarkBean;
import com.mujin.keji.collectionsystem.db.domain.VisitCountBean;
import com.mujin.keji.collectionsystem.db.domain.VisitRuleBean;
import com.mujin.keji.collectionsystem.module.login.dto.UserDto;

@Database(entities = {UserDto.class, SignBean.class, VisitRuleBean.class,
        VisitCountBean.class, VisitApplyBean.class, SaveVisitRecordBean.class,
        VisitApplyDetailBean.class, VisitApplyMarkBean.class},version = 2,exportSchema = false)
public abstract class AppDataBase extends RoomDatabase {

    private static  AppDataBase appDataBase;
    //对外提供需要操作数据库的DAO
    public abstract UserDao getUserDao();

    public abstract SignDao getSignDao();

    public abstract VisitRuleDao getVisitRuleDao();

    public abstract VisitDao getVisitDao();

    public abstract VisitRecordDao getVisitRecord();

    /**
     * 以单实例的形式初始化数据 并对外提供  AppDataBase实例
     * @param context
     * @return
     */
    public static AppDataBase getInstance(Context context){
        if(appDataBase==null){
            synchronized (AppDataBase.class){
                if(appDataBase==null){
                    //"user" 为数据库名
                    appDataBase = Room.databaseBuilder(context.getApplicationContext(),AppDataBase.class,"visit_db").build();
                }
            }
        }
        return appDataBase;
    }

}
